//
//  ZallPickerView.h
//  ZJS
//
//  Created by so on 16/6/17.
//  Copyright © 2016年 zall. All rights reserved.
//

#import "ZallBorderView.h"
#import "ZallBaseItem.h"

NS_ASSUME_NONNULL_BEGIN

/*
 The 3 components Sample:
 NSMutableArray *items0 = [NSMutableArray array];
 for(NSInteger c0 = 0; c0 < 3; c0 ++) {
    NSMutableArray *items1 = [NSMutableArray array];
    for(NSInteger c1 = 0; c1 < 24; c1 ++) {
        NSMutableArray *items2 = [NSMutableArray array];
        for(NSInteger c2 = 0; c2 < 60; c2 ++) {
            NSString *string2 = [NSString stringWithFormat:@"%@分", [@(c2) stringValue]];
            ZallPickerItem *item2 = [ZallPickerItem itemWithText:string2 items:nil];
            [items2 addObject:item2];
        }
        NSString *string1 = [NSString stringWithFormat:@"%@时", [@(c1) stringValue]];
        ZallPickerItem *item1 = [ZallPickerItem itemWithText:string1 items:items2];
        [items1 addObject:item1];
    }
    NSString *string0 = [NSString stringWithFormat:@"%@日", [@(c0) stringValue]];
    ZallPickerItem *item0 = [ZallPickerItem itemWithText:string0 items:items1];
    [items0 addObject:item0];
 }
 
 ZallPickerView *pickerView = [[ZallPickerView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 200.0f) components:3 items:items0];
 [pickerView showInView:self.view];
 */

@class ZallPickToolView;
@class ZallPickerItem;
@protocol ZallPickerViewDelegate;

/**
 *  @brief  选择器，集合了蒙层、工具条、系统选择器
 */
@interface ZallPickerView : ZallBorderView {
    __weak id <ZallPickerViewDelegate> _delegate;
}

/**
 *  @brief  回调代理，可为空
 */
@property (weak, nonatomic, nullable) id <ZallPickerViewDelegate> delegate;

/**
 *  @brief  初始化方法，components为列数量，items不可为空
 */
- (instancetype)initWithFrame:(CGRect)frame components:(NSInteger)components items:(NSArray <__kindof ZallPickerItem *> * _Nonnull)items;

/**
 *  @brief  设置停留位置
 */
- (void)selectText:(NSString * _Nonnull)text inComponent:(NSInteger)component animated:(BOOL)animated;

/**
 *  @brief  显示在view上，如果view为nil则自动设置为keywindow，默认为从底部出来
 */
- (void)showInView:(UIView * _Nullable)view;
- (void)showFromRect:(CGRect)rect inView:(UIView * _Nullable)view animated:(BOOL)animated;

/**
 *  @brief  使消失的方法，默认有动画，默认为从底部消失
 */
- (void)dismiss;
- (void)dismissAnimated:(BOOL)animated;

@end


@interface ZallPickerView (PickSubviews)

/**
 *  @brief  是否显示工具条
 */
@property (nonatomic, getter=isShowControls) BOOL showControls;

/**
 *  @brief  工具条
 */
@property (readonly, nonnull) ZallPickToolView *toolView;

/**
 *  @brief  单元格高度，default is 40.0f
 */
@property (nonatomic) CGFloat rowHeight;

/**
 *  @brief  系统选择器
 */
@property (readonly, nonnull) UIPickerView *pickerView;

/**
 *  @brief  选中的数据
 */
- (NSArray <__kindof ZallPickerItem *> * _Nonnull)selectedItems;

@end


/**
 *  @brief  选择器的代理
 注意:
 不会调用 pickerView:titleForRow:forComponent:
 而是调用 pickerView:attributedTitleForRow:forComponent:
 */
@protocol ZallPickerViewDelegate <UIPickerViewDelegate>
@optional
- (void)pickerView:(ZallPickerView * _Nonnull)pickerView leftButtonTouched:(UIButton * _Nonnull)leftButton;
- (void)pickerView:(ZallPickerView * _Nonnull)pickerView rightButtonTouched:(UIButton * _Nonnull)rightButton;
- (void)pickerView:(ZallPickerView * _Nonnull)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component attributedText:(NSAttributedString *_Nullable)attributedText;
@end


/**
 *  @brief  选择器上方控制器视图类
 */
@interface ZallPickToolView : ZallBorderView
/**
 *  @brief  左侧按钮，默认 “取消”
 */
@property (strong, nonatomic, readonly, nonnull) UIButton *leftButton;

/**
 *  @brief  右侧按钮， 默认 “完成”
 */
@property (strong, nonatomic, readonly, nonnull) UIButton *rightButton;
@end


/**
 *  @brief  选择器数据类型
 */
@interface ZallPickerItem : ZallBaseItem

/**
 *  @brief  富文本
 */
@property (copy, nonatomic, nonnull) NSAttributedString *attributedText;

/**
 *  @brief  嵌套的子数据
 */
@property (strong, nonatomic, nullable) NSArray <__kindof ZallPickerItem *> *items;

/**
 *  @brief  初始化方法
 */
+ (instancetype)itemWithText:(NSString * _Nonnull)text;
+ (instancetype)itemWithText:(NSString * _Nonnull)text items:(NSArray <__kindof ZallPickerItem *>  * _Nullable)items;
+ (instancetype)itemWithAttributedText:(NSAttributedString * _Nonnull)attributedText items:(NSArray <__kindof ZallPickerItem *>  * _Nullable)items;

@end

NS_ASSUME_NONNULL_END
